// packagMy/pages/personal/myFootprint/myFootprint.js
import { pageProduct } from '../../../../config/config'
//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
    listData: [],
    page: 1,
    rows: 10,
    nomoreData: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success (res) {
        let statusBarHeight = res.statusBarHeight + 65
        console.log(statusBarHeight)
        that.setData({
          titleHeight: statusBarHeight + 'px'
        })
      }
    })
    that.getList()
  },
  // 获取足迹列表
  getList() {
    let that = this
    let formdata = {}
    formdata.page = that.data.page
    formdata.rows = that.data.rows
    app.reqFun.requestForm('POST',pageProduct,formdata,(res)=>{
      if(res.data.success === 1) {
        let records = res.data.data.records
        let myDate = new Date()
        let toDay = '0' + myDate.toLocaleDateString().split('/')[1] + '月' + myDate.toLocaleDateString().split('/')[2] + '日'
        for (let h = 0; h < records.length; h++) {
          let date = records[h].accessTime.split('-')
          records[h].accessTime = date[0] + '月' + date[1] + '日'
          if (toDay == records[h].accessTime) {
            records[h].accessTime = '今天'
          }
        }
        if (res.data.data.total < that.data.rows * that.data.page) {
          that.setData({
            nomoreData: true
          })
        }
        that.setData({
          listData: that.data.listData.concat(records)
        })
        let listData = that.data.listData
        let tempArr = [], newArr = []
        for (let i = 0; i < listData.length; i++) {
          if (tempArr.indexOf(listData[i].accessTime) === -1) {
            newArr.push({
              accessTime: listData[i].accessTime,
              appUmsMemberFootprintDataDtos: listData[i].appUmsMemberFootprintDataDtos
            })
            tempArr.push(listData[i].accessTime);
          } else {
            for (let j = 0; j < newArr.length; j++) {
              if (newArr[j].accessTime == listData[i].accessTime) {
                newArr[j].appUmsMemberFootprintDataDtos =newArr[j].appUmsMemberFootprintDataDtos.concat(listData[i].appUmsMemberFootprintDataDtos)
              }
            }
          }
        }
        that.setData({
          listData: newArr
        })
      }
    })
  },
   // 商品详情
   goodsInfo(option) {
    let skuid = option.currentTarget.dataset.skuid
    wx.navigateTo({
        url: '/packageShop/pages/goodsInfo/goodsInfo?id=' + skuid,
    })
  },
  goreBack(e){
    wx.navigateBack({
      delta: 1,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.nomoreData) {
      this.setData({
        page: this.data.page + 1
      })
      this.getList()
    }
  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})